<template>
  <div class="Template8__layer"
       :style="{backgroundColor: formData.maskColor, width: ((editorDevice === 'desktop' || editorDevice === 'all') &&  formData.showDevice !== 'mobile') ? '100%' : '475px', transform: ((editorDevice === 'desktop' || editorDevice === 'all') &&  formData.showDevice !== 'mobile') ? 'none': 'scale(0.8)'}">
    <div class="Template8PcWrap"
         :style="{background: `none center center / cover no-repeat scroll ${formData.baseMap1}`,  width: ((editorDevice === 'desktop' || editorDevice === 'all') &&  formData.showDevice !== 'mobile') ? '950px' : 'calc(100% - 40px)'}"
         style="position: absolute; transform: scale(1);"
    >
      <div class="popupBox-init">
        <div class="subscribe-popup-init">
          <div class="subscribe-popup-main-image subscribe-popup-main-flex"
               :style="{backgroundColor: formData.imageColor}">
            <img :src="formData.imageUrl">
          </div>
          <div class="subscribe-popup-main-form subscribe-popup-main-flex">
            <div class="subscribe-popup-main subscribeModel">
              <form id="subpopup-form-ajax" method="post">
                <p class="welcome" role="heading" aria-level="1">Welcome To {{siteInfo.name}}</p>
                <div class="discount" v-html="formData.popupTitle"></div>
                <div class="supplement" v-html="formData.programme"></div>
                <div v-if="formData.showInput">
                  <label for="subscribeEmail" class="ariaClass">Email Address</label>
                  <input class="subscribe-input" type="email" name="email" placeholder="Enter Your Email Here"
                         aria-labelledby="email adress">
                  <div class="Template8__btn get-coupon"
                       :style="{backgroundColor: formData.btnBackgroundColor, borderColor: formData.btnBackgroundColor}"
                       v-html="formData.btnText"></div>
                  <p class="no-thanks">No, thanks.</p>
                </div>
                <div class="subscribe-popup-advantage">
                  <div v-if="formData.showFreightPlan"
                       :style="{color: formData.freightPlanTextColor, backgroundColor: formData.freightPlanBackgroundColor}">
                    <img :src="formData.freightPlanImage" alt="track order">
                    <span>{{ formData.freightPlanText }}</span>
                    <span>{{ formData.freightPlanTextSubhead }}</span>
                  </div>
                  <div v-if="formData.showExchange"
                       :style="{color: formData.exchangeTextColor, backgroundColor: formData.exchangeBackgroundColor}">
                    <img :src="formData.exchangeImage" alt="return">
                    <span>{{ formData.exchangeText }}</span>
                    <span>{{ formData.exchangeTextSubhead }}</span>
                  </div>
                </div>
              </form>
            </div>
          </div>
        </div>
        <div class="subscribe-popup-close popup-subpopup-init" role="button" aria-label="Close subscribe popup">
          <img src="https://cdn.shoplazzay.com/1712653518799d5h44d.png" alt="Close subscribe popup">
        </div>
      </div>
    </div>
    <div class="Template8__mode_edit"></div>
  </div>
</template>

<script>
import {parseCountDownTimeData} from '@/utils/utils';
import {mapGetters} from 'vuex';
export default {
    name: 'FlashSale',
    props: {
        formData: {
            type: Object,
            default: () => ({})
        },
        deviceName: {
            type: String,
            default: 'desktop'
        }
    },
    watch: {
        deviceName (newValue) {
            this.editorDevice = newValue;
        },
        editor (newValue) {
            this.editorDevice = newValue;
        }
    },
    data () {
        return {
            editorDevice: 'all'
        };
    },
    computed: {
        ...mapGetters({editor: 'editorDevice', siteList: 'siteList'}),
        siteId () {
            return this.$store.state.user.siteId;
        },
        siteInfo () {
            let info = this.siteList.find(res => res.id === Number(this.siteId));
            return info;
        }
    },
    methods: {
        timeStr (time) {
            console.log(parseCountDownTimeData(time));
            return parseCountDownTimeData(time);
        },
        getTimeStr (time, index) {
            if (time < 10) {
                if (index === 0) {
                    return 0;
                }
                return time;
            }
            return time.toString().charAt(index);
        },
        handleClose () {
            this.$emit('close');
        }
    }
};
</script>

<style lang="scss" scoped>
.popupBox-init .subscribe-popup-init .subscribe-popup-main-image {
  display: none;
}
.popupBox-init .subscribe-popup-close {
  position: absolute;
  top: 23px;
  right: 23px;
  cursor: pointer;
}
.popupBox-init .subscribe-popup-close img {
  width: 24px;
  height: 24px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main {
  padding: 60px 24px;
  text-align: center;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  margin-top: 30px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div {
  width: 210px;
  height: 100px;
  background: #fbf5ef;
  margin-right: 12px;
  text-align: center;
  flex: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div img {
  width: 24px;
  margin-bottom: 12px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(2) {
  font-family: Graphik-Medium-Web;
  font-size: 13px;
  line-height: 13px;
  margin-bottom: 5px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(3) {
  font-size: 12px;
  line-height: 12px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="password"], .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="email"], .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="text"] {
  font-family: Graphik-Regular-Web;
  line-height: 14px;
  width: 100%;
  height: 48px;
  border: 1px solid #e8e8e8;
  border-radius: 1px;
}
.subscribe-popup-main.subscribeModel input[type="password"], .subscribe-popup-main.subscribeModel input[type="email"] {
  padding: 0;
  text-align: center;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .welcome {
  font-size: 18px;
  line-height: 29px;
  margin-bottom: 24px
}

.popupBox-init .subscribe-popup-init .subscribe-popup-main .discount {
  font-size: 40px;
  line-height: 48px;
  margin-bottom: 5px
}

.popupBox-init .subscribe-popup-init .subscribe-popup-main .supplement {
  font-size: 14px;
  line-height: 23px;
  margin-bottom: 26px
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .get-coupon {
  font-family: Graphik-Medium-Web;
  width: 100%;
  height: 48px;
  line-height: 48px;
  border-radius: 1px;
  text-decoration: none;
  color: #fff;
  background-color: #2c2c2c;
}
.Template8__layer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .Template8PcWrap {
    position: relative;
    display: flex;
    flex-direction: column;
    z-index: 3;
    line-height: 1.5;
    text-align: center;
    color: #000;
    font-size: 14px;
    p{
      padding: 0;
      margin: 0;
    }

    .Template8__img-wrapper {
      padding: 30px 65px 46px;
      width: 100%;
      height: 300px;

      .Template8__title, .Template8__desc {
        margin: 0 auto;
      }
      .Template8__title{
        max-height: 100px;
        overflow : hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 5;
        -webkit-box-orient: vertical;
      }

      .Template8__countdown {
        margin: 60px auto 0;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;

        .Template8__countdown_minute, .Template8__countdown_second {
          display: flex;
          flex-direction: row;
          align-items: center;

          .Template8__countdown_word {
            margin-right: 5px;
            width: 42px;
            height: 69px;
            line-height: 69px;
            border-radius: 2px;
            font-weight: bold;
            font-size: 30px;
          }

          .Template8__countdown_colon {
            margin: 0 3px;
            font-weight: bold;
            font-size: 30px;
          }
        }
      }
    }

    .Template8__content {
      padding: 40px;
      &.isMobile{
        padding: 20px 120px;
      }

      .Template8__coupon {
        position: relative;
        margin: 0 auto 20px;
        height: 50px;
        line-height: 50px;
        font-size: 24px;
        font-weight: bold;
        border: 2px dashed #b70000;
        border-radius: 4px;
        cursor: pointer;
      }

      .Template8__btn {
        display: inline-block;
        padding: 0 20px;
        min-width: 240px;
        height: 50px;
        line-height: 50px;
        background-color: #000;
        border: 1px solid #000;
        border-radius: 4px;
        outline: none;
        cursor: pointer;
      }
    }
  }

  .Template8__close-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 20px;
    height: 20px;
    line-height: 16px;
    font-size: 14px;
    color: #fff;
    cursor: pointer;
  }
}
@media screen and (max-width: 1280px) and (min-width:768px) {
  .popupBox-init {
    max-width:560px;
    //max-height: 92%;
    top: 50%;
    transform: translate(-50%, -50%)
  }

  .popupBox-init .subscribe-popup-init {
    max-width: 100%
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main {
    padding: 72px 64px 80px 64px
  }

  .popupBox .subscribe-popup .subscribe-popup-main .discount,.popupBox .subscribe-popup .subscribe-popup-main .login-title {
    font-size: 40px;
    line-height: 48px
  }
}

@media screen and (min-width: 1281px) {
  .popupBox-init {
    width: 100%;
    max-width: 1000px;
    //max-height: 92%;
    background: #fff;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: height .3s;
    overflow-y: auto;
    z-index: 1010
  }

  .popupBox-init .subscribe-popup-close {
    position: absolute;
    top: 23px;
    right: 23px;
    cursor: pointer
  }

  .popupBox-init .subscribe-popup-close img {
    width: 24px;
    height: 24px
  }

  .popupBox-init .subscribe-popup-public {
    max-width: 480px;
    margin: auto
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main {
    padding: 80px 24px;
    text-align: center
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .welcome {
    font-size: 18px;
    line-height: 1.61;
    margin-bottom: 24px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .discount {
    font-size: 40px;
    line-height: 45px;
    margin-bottom: 5px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .supplement {
    line-height: 23px;
    margin-bottom: 26px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .login-title {
    font-size: 40px;
    line-height: 45px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .font-F {
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .coupon-message {
    font-size: 22px;
    line-height: 18px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .coupon-message span {
    color: #bc836d
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .form-box {
    text-align: left
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .form-box label {
    display: block;
    line-height: 11px;
    margin-top: 20px;
    margin-bottom: 15px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .form-box label:first-of-type {
    margin-top: 0
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="password"], .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="email"], .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="text"] {
    line-height: 14px;
    width: 100%;
    height: 48px;
    border: 1px solid #e8e8e8;
    border-radius: 1px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="password"]:focus, .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="email"]:focus, .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="text"]:focus {
    border: 1px solid #2c2c2c
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="password"].error-inputStyle, .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="email"].error-inputStyle, .popupBox-init .subscribe-popup-public .subscribe-popup-main input[type="text"].error-inputStyle {
    color: #bc836d;
    border: 1px solid #bc836d
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .error-messsage {
    display: none;
    margin-top: 10px;
    justify-content: center
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .error-messsage img {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 3px;
    vertical-align: top
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .error-messsage span {
    display: inline-block;
    font-size: 13px;
    line-height: 14px;
    color: #bc836d;
    vertical-align: top
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .get-coupon {
    width: 100%;
    height: 48px;
    line-height: 48px;
    border-radius: 1px;
    text-transform: uppercase;
    text-decoration: none;
    color: #fff;
    background-color: #2c2c2c
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .get-coupon:hover {
    background-color: #bc836d;
    border-color: #bc836d
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .no-thanks {
    display: inline-block;
    line-height: 13px;
    text-decoration: underline;
    cursor: pointer
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    margin-top: 30px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div {
    width: 210px;
    height: 100px;
    background: #fbf5ef;
    margin-right: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div:last-of-type {
    margin-right: 0
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div img {
    width: 24px;
    margin-bottom: 12px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div span {
    display: block
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(2) {
    font-size: 13px;
    line-height: 13px;
    margin-bottom: 5px
  }

  .popupBox-init .subscribe-popup-public .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(3) {
    font-size: 12px;
    line-height: 12px
  }

  .popupBox-init .subscribe-popup-init {
    max-width: 100%;
    margin: auto;
    display: flex;
    min-height:550px;
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main-flex {
    width: 50%
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main-image {
    display: inline-block;
    position: relative;
    overflow: hidden;
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main-image img{
    height: 100%;
    object-fit: cover;
  }

  img {
    border: 0;
    vertical-align: middle;
    max-width: 100%;
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main {
    height: 100%;
    padding: 0 35px;
    text-align: center
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main > form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .welcome {
    font-size: 18px;
    line-height: 29px;
    margin-bottom: 24px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .discount {
    font-size: 40px;
    line-height: 48px;
    margin-bottom: 5px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .supplement {
    font-size: 14px;
    line-height: 23px;
    margin-bottom: 26px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .login-title {
    font-size: 40px;
    line-height: 45px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .font-F {
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .coupon-message {
    font-size: 22px;
    line-height: 18px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .coupon-message span {
    color: #bc836d
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .form-box {
    text-align: left
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .form-box label {
    display: block;
    line-height: 11px;
    margin-top: 20px;
    margin-bottom: 15px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .form-box label:first-of-type {
    margin-top: 0
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="password"], .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="email"], .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="text"] {
    line-height: 14px;
    width: 100%;
    height: 48px;
    border: 1px solid #e8e8e8;
    border-radius: 1px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="password"]:focus, .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="email"]:focus, .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="text"]:focus {
    border: 1px solid #2c2c2c
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="password"].error-inputStyle, .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="email"].error-inputStyle, .popupBox-init .subscribe-popup-init .subscribe-popup-main input[type="text"].error-inputStyle {
    color: #bc836d;
    border: 1px solid #bc836d
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .error-messsage {
    display: none;
    margin-top: 10px;
    justify-content: center
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .error-messsage img {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 3px;
    vertical-align: top
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .error-messsage span {
    display: inline-block;
    font-size: 13px;
    line-height: 14px;
    color: #bc836d;
    vertical-align: top
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .get-coupon {
    width: 100%;
    height: 48px;
    line-height: 48px;
    border-radius: 1px;
    text-decoration: none;
    color: #fff;
    background-color: #2c2c2c
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .get-coupon:hover {
    background-color: #bc836d;
    border-color: #bc836d
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .no-thanks {
    display: inline-block;
    font-size: 14px;
    line-height: 23px;
    text-decoration: underline;
    cursor: pointer
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    margin-top: 24px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div {
    width: 210px;
    height: 100px;
    background: #fbf5ef;
    margin-right: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div:last-of-type {
    margin-right: 0
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div img {
    width: 24px;
    margin-bottom: 12px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div span {
    display: block
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(2) {
    font-size: 13px;
    line-height: 13px;
    margin-bottom: 5px
  }

  .popupBox-init .subscribe-popup-init .subscribe-popup-main .subscribe-popup-advantage div span:nth-child(3) {
    font-size: 12px;
    line-height: 12px
  }
}
.subscribe-popup-main.subscribeModel .PrivacyPolicy {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .PrivacyPolicy .PrivacyPolicy-hook {
  position: relative;
  width: 22px;
  height: 22px;
  border: 1px solid #2c2c2c;
  background: #fff;
  margin-right: 10px;
}
.popupBox-init .subscribe-popup-init .subscribe-popup-main .PrivacyPolicy .PrivacyPolicy-hook img {
  width: 12px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.subscribe-popup-main.subscribeModel .get-coupon {
  margin-top: 15px;
}
.ariaClass{
  display: none;
}
</style>
<style lang="scss">
.Template8__btn {
  p {
    margin: 0;
  }
}
.popupBox-init .discount p {
  padding: 0;
  margin: 0;
}
</style>
